//
//  UIView+returnBlock.m
//  companyDetail
//
//  Created by WJC on 2018/12/11.
//

#import "UIView+returnBlock.h"
#import <objc/runtime.h>
static const char idKey;
static const char voidKey;
static const char cityArea;
static const char area;
@implementation UIView (returnBlock)
    // 设置
    // id object 源对象 -指定我们需要绑定的对象，e.g ,给UIButton添加事件，给Class加属性
    // const void *key 设置一个静态常亮，也就是Key 值，通过这个我们可以找到我们关联对象的那个数据值
    // id value 关联的对象,e.g 添加的事件或者属性
    // objc_AssociationPolicy policy 关联的策略

-(void)setIdBlock:(void (^)(id))idBlock{
    objc_setAssociatedObject(self, &idKey, idBlock, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(void (^)(id))idBlock{
    return objc_getAssociatedObject(self, &idKey);
}
-(void)setVoidBlock:(void (^)(void))voidBlock{
    objc_setAssociatedObject(self, &voidKey, voidBlock, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(void (^)(void))voidBlock{
    return objc_getAssociatedObject(self, &voidKey);
}



-(void)setAddressReturnBlock:(void (^)(NSString *cityArea ,NSString *addressInfo))addressReturnBlock{
    return objc_setAssociatedObject(self,  &cityArea, addressReturnBlock, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

-(void (^)(id))addressReturnBlock{
    return objc_getAssociatedObject(self, &cityArea);
}


-(void)setAddressAreaBlock:(void (^)(NSString *, NSString *, NSString *))addressAreaBlock{
    return objc_setAssociatedObject(self,  &area, addressAreaBlock, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(void (^)(void))addressAreaBlock{
    return objc_getAssociatedObject(self, &area);
}

@end
